package com.greatmap.gtwithpg.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.greatmap.gtwithpg.entity.YjjbntPo;
import com.greatmap.gtwithpg.service.ShpService;
import com.greatmap.utils.ShpUtil;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shp")
public class ShpController {

    @Autowired
    private ShpService shpService;

    @RequestMapping("/hello")
    public String test(){
        return "hello";
    }

    @RequestMapping("/getShp")
    public JSONObject getShpBy(Integer id){
        YjjbntPo shp = shpService.getShpBy(id);
        try {
            Geometry geometry = ShpUtil.Wkb2Geom(shp.getGeom());
            shp.setGeom(geometry.toString());
        } catch (ParseException e) {
            System.out.println(shp.getId()+"空间对象转换失败！");
        }
        return (JSONObject) JSON.toJSON(shp);

    }
}
